<?php
/**
 * 链表结点类
 */

namespace Xxb\XxbPhpAlgo;

class LinkedListNode
{
    /**
     * @var mixed 数据值
     */
    private $value;

    /**
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param mixed $value
     */
    public function setValue($value)
    {
        $this->value = $value;
    }

    /**
     * @return LinkedListNode|null
     */
    public function getNext()
    {
        return $this->next;
    }

    /**
     * @param LinkedListNode|null $next
     */
    public function setNext($next)
    {
        if (!is_null($next) && !($next instanceof self)) {
            throw new \TypeError('next node illegal.');
        }
        $this->next = $next;
    }

    /**
     * @var self|null 下一个结点
     */
    private $next;

    /**
     * LinkedListNode constructor.
     *
     * @param null $value
     * @param null $next
     */
    public function __construct($value = null, $next = null)
    {
        if (!is_null($next) && !($next instanceof self)) {
            throw new \TypeError('node init error, next node illegal.');
        }

        $this->value = $value;
        $this->next = $next;
    }
}
